package com.ruoyi.web.controller.market.account;

import java.util.List;
import java.util.Map;

import com.ruoyi.db.domain.ProductInfo;
import com.ruoyi.product.service.IProductInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.AccountItemProduct;
import com.ruoyi.account.service.IAccountItemProductService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.AccountItemProductWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品账户信息Controller
 * 
 * @author ruoyi
 * @date 2023-02-02
 */
@Controller
@RequestMapping("/account/itemProduct")
public class AccountItemProductController extends BaseController
{
    private String prefix = "account/itemProduct";

    @Autowired
    private IAccountItemProductService accountItemProductService;
    @Autowired
    private IProductInfoService productInfoService;

    @RequiresPermissions("account:itemProduct:view")
    @GetMapping()
    public String itemProduct(ModelMap modelMap)
    {
        // 产品信息
        List<Map<String, Object>> productMapList = productInfoService.listMap(new ProductInfo());
        modelMap.put("productList", productMapList);

        return prefix + "/itemProduct";
    }

    /**
     * 查询产品账户信息列表
     */
    @RequiresPermissions("account:itemProduct:view")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AccountItemProduct accountItemProduct)
    {
        startPage();
        List<Map<String, Object>> mapList = accountItemProductService.selectAccountItemProductListMap(accountItemProduct);
        mapList = new AccountItemProductWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出产品账户信息列表
     */
    @RequiresPermissions("account:itemProduct:export")
    @Log(title = "产品账户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AccountItemProduct accountItemProduct)
    {
        List<AccountItemProduct> list = accountItemProductService.selectAccountItemProductList(accountItemProduct);
        ExcelUtil<AccountItemProduct> util = new ExcelUtil<AccountItemProduct>(AccountItemProduct.class);
        return util.exportExcel(list, "产品账户信息数据");
    }

    /**
     * 新增产品账户信息
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        List<Map<String, Object>> productMapList = productInfoService.listMap(new ProductInfo());
        modelMap.put("productList", productMapList);
        return prefix + "/add";
    }

    /**
     * 新增保存产品账户信息
     */
    @RequiresPermissions("account:itemProduct:add")
    @Log(title = "产品账户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AccountItemProduct accountItemProduct)
    {
        return toAjax(accountItemProductService.insertAccountItemProduct(accountItemProduct));
    }

    /**
     * 修改产品账户信息
     */
    @RequiresPermissions("account:itemProduct:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AccountItemProduct accountItemProduct = accountItemProductService.selectAccountItemProductById(id);
        mmap.put("accountItemProduct", accountItemProduct);
        return prefix + "/edit";
    }

    /**
     * 修改保存产品账户信息
     */
    @RequiresPermissions("account:itemProduct:edit")
    @Log(title = "产品账户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AccountItemProduct accountItemProduct)
    {
        return toAjax(accountItemProductService.updateAccountItemProduct(accountItemProduct));
    }

    /**
     * 删除产品账户信息
     */
    @RequiresPermissions("account:itemProduct:remove")
    @Log(title = "产品账户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(accountItemProductService.deleteAccountItemProductByIds(ids));
    }
}
